home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
vbdatabs
/
vbdspec.txt
< prev
next >
Wrap
Text File
|
1999-03-30
|
15KB
|
304 lines
#######################
#### Start of File ####
#######################
-----------------------------------------------------------------
File Name: vbdspec.txt
Contents: VBD Specs Sheet
-----------------------------------------------------------------
Variable Block Database Version 1031, Revision A
TOPICS:
-------
Overview
VBD File Format
VBD File Specs
Platforms
OVERVIEW:
---------
The Variable Block Database is a file format used to store any
type of variable-length binary data in re-sizeable blocks. The
VBD file format was originally created to store persistent
objects in disk files. A persistent object refers to an object
that saves its state between program invocations. The VBD file
format is not limited to storing persistent objects. Any type of
data can be stored and manipulated in a VBD file. VBD files have
this capability because the methods by which any data type is
stored or retrieved must be defined within the application.
VBD FILE FORMAT:
----------------
Every VBD file contains a file header, an optional static storage
area, and a dynamic storage area where variable blocks of data
are stored. The file header is composed of six fields and is a
total of 28 bytes in length:
(1) Free space field - stores a pointer to the first block of
de-allocated heap space (4 bytes)
(2) End of file field - stores a pointer to the address of the
last byte in the file (4 bytes)
(3) Start of heap field - stores a pointer to the start of the
dynamic storage area (4 bytes)
(4) Highest block field - stores a pointer to the highest
allocated block (4 bytes)
(5) Signature field - signature used to identify the file type (8
bytes)
(6) Version field - used to identify the VBD file version
number(4 bytes)
This header is used to store information needed by the allocation
functions, a signature, and a version number. The static data
area is used to store fixed data that cannot be altered by any of
the dynamic allocation routines. The size of the static data must
by specified by the application that creates the VBD file. If no
static area is specified then the dynamic data area will start
directly after the VBD file header.
The first 28 bytes of the VBD file (file addresses 0 - 28) will
always contain the VBD header. If a static area is requested by
the application, the static area will occupy the bytes requested.
For example: if an application request 20 bytes to be reserved
for a static data area when the file is created, then bytes 29
through 48 (file addresses 29 - 48) will be reserved. The dynamic
data area will start directly after that and occupy the rest of
the file. A pointer to the start of the dynamic storage area can
be calculated by adding the size of the VBD file header to the
size of the static data area.
The dynamic data area always starts out empty and grows when
variable data blocks are allocated. The "free space", "end of
file", and "start of heap" pointers stored in the VBD file header
are used to maintain the dynamic data area. The "start of heap"
pointer stores the address where the dynamic data area starts
(which is where the static area ends.) The "end of file" pointer
marks the end of the file and points to the location where the
file can be extended during block allocation.
Revision 'A' adds a 32-bit CRC checksum routine used to detect
any bit errors that occur during data storage. The CRC is based
on the Ethernet polynomial of 0x4C11DB7. A checksum is calculated
when data is written to the VBD file, this includes the block
header and the block data. The calculated checksum is then
compared to data actually stored on disk. If the calculated
checksum does not match the actual checksum, a bit error has
occurred during data storage. All bit errors must be handled by
the application since the type of data being stored is not known.
Revision 'A' reserves four bytes at the end of each block that
can be used by an application to store a 32-bit checksum with
each block. Each time a new block is allocated space is reserved
for the number of bytes requested plus four additional bytes. The
application is responsible for reading and writing the block
checksum since the type of data being stored is not known. The
use of a block checksum is optional and does not have to be used
to detect bit errors because of the built-in CRC checksum routine
used each time any data is stored. Some applications require the
use of block checksums to maintain the integrity of the file from
one program invocation to the next.
When blocks are de-allocated, the block is marked deleted and
left in the file. The size of the file is determined by the
number of blocks allocated and will remain the same no matter how
many blocks are deleted. The number of deleted blocks is
maintained in a non-contiguous list. Each block in the list
points to the next block in the list starting at a specified
address. The "free space" pointer in the VBD file header is used
to store the file address of the block where the free space list
starts.
The "highest block" pointer in the VBD file header is used to
store the address of the highest allocated variable block. It is
used by the application when it needs to index data starting at
the end of the file.
The signature and version fields in the VBD file header must be
set when a new file is created. The signature field is used to
determine if the file is of the correct type. If the "VBDFILE"
signature is not found then it is assumed that this is not a
valid VBD file. The eighth byte is used for all revision changes.
Version 1031 sets the revision letter to 'A' and performs
compatibility checks to ensure backward compatibility with
previous releases. Revision 'A' adds a 32-bit CRC checksum
routine and reserves space at the end of each block for an
application to write a 32-bit check-word.
The version field is to represent this file version number. A
version number is used to indicate that changes have been made to
the application used to create VBD files. Version numbers can be
used inside of an application to conditionally perform certain
operations based on its value. This will ensure backward
compatibility with previous versions.
Variable Block (VB) headers manage all the variable data blocks
created inside the dynamic data area. Block headers are used to
mark the start of a variable data block. Every time a block is
allocated a block header is written to the file. Allocation works
by writing the block header and then reserving a specified number
of bytes for the data that will be stored in the block. Revision
'A' reserves four bytes at the end of the block to allow the
application to store a block checksum. After the space is
allocated, the application is responsible for writing the data to
the file starting at the address after the block header. Each
block header contains four fields and is a total of 16 bytes in
length:
(1) Check word field - "0x0000FEFE" check word used for file
integrity checks (4 bytes)
(2) Length field - block length including the object, block
header, and CRC (4 bytes)
(3) Status field - stores the status of dynamic data stored in
the block (4 byte)
(4) Next deleted block field - stores a pointer to the next
deleted block (4 bytes)
The VB header "check word" field represents a 32-bit check word
used for file integrity checks and is used to maintain
synchronization within the VBD creator and the application.
Revision 'A' uses all 32 bits of the block check-word. In
previous releases the upper 16 bits of the block check-word was
reserved for a 16-bit CRC. Revision 'A' implements a 32-bit CRC
routine and reserves four bytes at the end of each block for a
32-bit checksum. If the check word value is changed, the file
will no longer be compatible with previous releases.
The "length" field stores the length of the object plus the size
of the block header and the size of the block's CRC checksum
value. This field is used to index the file block by block. By
reading this value the application will always k